/*
 * File: Fu_CenCoord.c
 *
 * Code generated for Simulink model 'Fu_CenCoord'.
 *
 * Model version                  : 1.581
 * Simulink Coder version         : 8.2 (R2012a) 29-Dec-2011
 * TLC version                    : 8.2 (Dec 29 2011)
 * C/C++ source code generated on : Sun Jun 16 10:58:33 2013
 *
 * Target selection: ert.tlc
 * Embedded hardware selection: ARM Compatible->ARM Cortex
 * Code generation objectives: Unspecified
 * Validation result: Not run
 */

#include "Fu_CenCoord.h"
#include "Fu_CenCoord_private.h"

/* Named constants for Chart: '<S1>/Fu_CenCoord_StateMachine' */
#define Fu_CenCoord_IN_Drive           ((uint8_T)1U)
#define Fu_CenCoord_IN_LO_SPD          ((uint8_T)2U)
#define Fu_CenCoord_IN_PreDrive        ((uint8_T)3U)

/* Exported block signals */
uint8_T Coord_States;                  /* '<S1>/Fu_CenCoord_StateMachine' */
boolean_T Coord_FlgRdyForDrv;          /* '<S1>/Fu_CenCoord_StateMachine' */
boolean_T Coord_FlgRunReq;             /* '<S1>/Fu_CenCoord_StateMachine' */

/* Block states (auto storage) */
D_Work_Fu_CenCoord Fu_CenCoord_DWork;

/* Real-time model */
RT_MODEL_Fu_CenCoord Fu_CenCoord_M_;
RT_MODEL_Fu_CenCoord *const Fu_CenCoord_M = &Fu_CenCoord_M_;

/* Model step function */
void Fu_CenCoord_step(void)
{
  int32_T tmp;

  /* Chart: '<S1>/Fu_CenCoord_StateMachine' incorporates:
   *  Inport: '<Root>/In1'
   */
  /* Gateway: Fu_CenCoord/Fu_CenCoord_StateMachine */
  /* During: Fu_CenCoord/Fu_CenCoord_StateMachine */
  if (Fu_CenCoord_DWork.is_active_c1_Fu_CenCoord == 0) {
    /* Entry: Fu_CenCoord/Fu_CenCoord_StateMachine */
    Fu_CenCoord_DWork.is_active_c1_Fu_CenCoord = 1U;

    /* Entry Internal: Fu_CenCoord/Fu_CenCoord_StateMachine */
    /* Transition: '<S2>:5' */
    Fu_CenCoord_DWork.is_c1_Fu_CenCoord = Fu_CenCoord_IN_PreDrive;

    /* Entry 'PreDrive': '<S2>:1' */
    Coord_States = 0U;
    Coord_FlgRunReq = FALSE;
    Coord_FlgRdyForDrv = FALSE;
  } else {
    switch (Fu_CenCoord_DWork.is_c1_Fu_CenCoord) {
     case Fu_CenCoord_IN_Drive:
      /* During 'Drive': '<S2>:3' */
      if (RotSpd_St != 2) {
        /* Transition: '<S2>:16' */
        Fu_CenCoord_DWork.is_c1_Fu_CenCoord = Fu_CenCoord_IN_LO_SPD;

        /* Entry 'LO_SPD': '<S2>:2' */
        Coord_FlgRdyForDrv = TRUE;
        Coord_FlgRunReq = TRUE;
        Coord_States = 1U;
      }
      break;

     case Fu_CenCoord_IN_LO_SPD:
      /* During 'LO_SPD': '<S2>:2' */
      if (RotSpd_St == 2) {
        /* Transition: '<S2>:7' */
        Fu_CenCoord_DWork.is_c1_Fu_CenCoord = Fu_CenCoord_IN_Drive;

        /* Entry 'Drive': '<S2>:3' */
        Coord_States = 2U;
        Coord_FlgRunReq = TRUE;
        Coord_FlgRdyForDrv = TRUE;
      }
      break;

     default:
      /* During 'PreDrive': '<S2>:1' */
      if (Fu_CenCoord_DWork.loc_counter > 150) {
        /* Transition: '<S2>:6' */
        Fu_CenCoord_DWork.is_c1_Fu_CenCoord = Fu_CenCoord_IN_LO_SPD;

        /* Entry 'LO_SPD': '<S2>:2' */
        Coord_FlgRdyForDrv = TRUE;
        Coord_FlgRunReq = TRUE;
        Coord_States = 1U;
      } else {
        /* Transition: '<S2>:11' */
        tmp = Fu_CenCoord_DWork.loc_counter + 1;
        if (tmp > 65535) {
          tmp = 65535;
        }

        Fu_CenCoord_DWork.loc_counter = (uint16_T)tmp;
        Fu_CenCoord_DWork.is_c1_Fu_CenCoord = Fu_CenCoord_IN_PreDrive;

        /* Entry 'PreDrive': '<S2>:1' */
        Coord_States = 0U;
        Coord_FlgRunReq = FALSE;
        Coord_FlgRdyForDrv = FALSE;
      }
      break;
    }
  }

  /* End of Chart: '<S1>/Fu_CenCoord_StateMachine' */
}

/* Model initialize function */
void Fu_CenCoord_initialize(void)
{
  /* Registration code */

  /* initialize error status */
  rtmSetErrorStatus(Fu_CenCoord_M, (NULL));

  /* block I/O */

  /* exported global signals */
  Coord_States = 0U;
  Coord_FlgRdyForDrv = FALSE;
  Coord_FlgRunReq = FALSE;

  /* states (dwork) */
  (void) memset((void *)&Fu_CenCoord_DWork, 0,
                sizeof(D_Work_Fu_CenCoord));

  /* InitializeConditions for Chart: '<S1>/Fu_CenCoord_StateMachine' */
  Fu_CenCoord_DWork.is_active_c1_Fu_CenCoord = 0U;
  Fu_CenCoord_DWork.is_c1_Fu_CenCoord = 0U;
  Fu_CenCoord_DWork.loc_counter = 0U;
  Coord_FlgRdyForDrv = FALSE;
  Coord_States = 0U;
  Coord_FlgRunReq = FALSE;
}

/*
 * File trailer for generated code.
 *
 * [EOF]
 */
